package ch.bfh.abcmmh.view.detailview.streets;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Observable;
import java.util.Observer;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import ch.bfh.abcmmh.view.GUIController;

public class ImagePanel extends JPanel implements Observer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 679498100457574458L;
	private Image img;
	private GUIController guiController;

	public ImagePanel(GUIController guiController, String img, int width,
			int height, int pos) {
		this(guiController, new ImageIcon(img).getImage(), width, height,pos);

	}

	public ImagePanel(GUIController guiController, Image img, int width,
			int height, int pos) {
		
		this.img = new ImageIcon(getClass().getResource("/grass.jpg")).getImage();
		this.guiController = guiController;
		Dimension size = new Dimension(guiController.getLogicalStreetLenth(),
				height); // new Dimension(img.getWidth(null),
							// img.getHeight(null));
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
		setLayout(null);
		setLocation(0, pos);
		this.setOpaque(true);
	}

	public void paintComponent(Graphics g) {

		int max = guiController.getLogicalStreetLenth() / 1400;
		for (int i = 0; i < (max + 1); i++) {
			g.drawImage(img, i * 1400, 0, null);
		}

	}

	@Override
	public void update(Observable o, Object arg) {
	int scopepos = guiController.getDetailPosition();
		this.setLocation(-scopepos, (int) getLocation().getY());
		repaint();
		
	}
}